<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>libwebsockets: HTTP headers: create</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="libwebsockets.org-logo.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">libwebsockets
   </div>
   <div id="projectbrief">Lightweight C library for HTML5 websockets</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li class="current"><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__HTTP-headers-create.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">HTTP headers: create<div class="ingroups"><a class="el" href="group__http.html">HTTP</a></div></div>  </div>
</div><!--header-->
<div class="contents">
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga29b7d6d2ddfdbaff3d8b607e7e3151b6"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__HTTP-headers-create.html#ga29b7d6d2ddfdbaff3d8b607e7e3151b6">lws_add_http_header_status</a> (struct lws *wsi, unsigned int code, unsigned char **p, unsigned char *end)</td></tr>
<tr class="separator:ga29b7d6d2ddfdbaff3d8b607e7e3151b6"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga2b36bf44405755ff51c1939303b995a8"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__HTTP-headers-create.html#ga2b36bf44405755ff51c1939303b995a8">lws_add_http_header_by_name</a> (struct lws *wsi, const unsigned char *name, const unsigned char *value, int length, unsigned char **p, unsigned char *end)</td></tr>
<tr class="separator:ga2b36bf44405755ff51c1939303b995a8"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaf74adb761b22566ad70004882712dce1"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__HTTP-headers-create.html#gaf74adb761b22566ad70004882712dce1">lws_add_http_header_by_token</a> (struct lws *wsi, enum lws_token_indexes token, const unsigned char *value, int length, unsigned char **p, unsigned char *end)</td></tr>
<tr class="separator:gaf74adb761b22566ad70004882712dce1"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gacc76a5babcb4dce1b01b1955aa7a2faf"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__HTTP-headers-create.html#gacc76a5babcb4dce1b01b1955aa7a2faf">lws_add_http_header_content_length</a> (struct lws *wsi, unsigned long content_length, unsigned char **p, unsigned char *end)</td></tr>
<tr class="separator:gacc76a5babcb4dce1b01b1955aa7a2faf"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga4887605ff2242a54db3a7fa01f6f864b"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__HTTP-headers-create.html#ga4887605ff2242a54db3a7fa01f6f864b">lws_finalize_http_header</a> (struct lws *wsi, unsigned char **p, unsigned char *end)</td></tr>
<tr class="separator:ga4887605ff2242a54db3a7fa01f6f864b"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<h2>HTTP headers: Create</h2>
<p>These apis allow you to create HTTP response headers in a way compatible with both HTTP/1.x and HTTP/2.</p>
<p>They each append to a buffer taking care about the buffer end, which is passed in as a pointer. When data is written to the buffer, the current position p is updated accordingly.</p>
<p>All of these apis are LWS_WARN_UNUSED_RESULT as they can run out of space and fail with nonzero return. </p>
<h2 class="groupheader">Function Documentation</h2>
<a class="anchor" id="ga2b36bf44405755ff51c1939303b995a8"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_add_http_header_by_name </td>
          <td>(</td>
          <td class="paramtype">struct lws *&#160;</td>
          <td class="paramname"><em>wsi</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const unsigned char *&#160;</td>
          <td class="paramname"><em>name</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const unsigned char *&#160;</td>
          <td class="paramname"><em>value</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>length</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned char **&#160;</td>
          <td class="paramname"><em>p</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned char *&#160;</td>
          <td class="paramname"><em>end</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
<p><a class="el" href="group__HTTP-headers-create.html#ga2b36bf44405755ff51c1939303b995a8">lws_add_http_header_by_name()</a> - append named header and value</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">wsi</td><td>the connection to check </td></tr>
    <tr><td class="paramname">name</td><td>the hdr name, like "my-header" </td></tr>
    <tr><td class="paramname">value</td><td>the value after the = for this header </td></tr>
    <tr><td class="paramname">length</td><td>the length of the value </td></tr>
    <tr><td class="paramname">p</td><td>pointer to current position in buffer pointer </td></tr>
    <tr><td class="paramname">end</td><td>pointer to end of buffer</td></tr>
  </table>
  </dd>
</dl>
<p>Appends name: value to the headers </p>

</div>
</div>
<a class="anchor" id="gaf74adb761b22566ad70004882712dce1"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_add_http_header_by_token </td>
          <td>(</td>
          <td class="paramtype">struct lws *&#160;</td>
          <td class="paramname"><em>wsi</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">enum lws_token_indexes&#160;</td>
          <td class="paramname"><em>token</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const unsigned char *&#160;</td>
          <td class="paramname"><em>value</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>length</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned char **&#160;</td>
          <td class="paramname"><em>p</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned char *&#160;</td>
          <td class="paramname"><em>end</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
<p><a class="el" href="group__HTTP-headers-create.html#gaf74adb761b22566ad70004882712dce1">lws_add_http_header_by_token()</a> - append given header and value</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">wsi</td><td>the connection to check </td></tr>
    <tr><td class="paramname">token</td><td>the token index for the hdr </td></tr>
    <tr><td class="paramname">value</td><td>the value after the = for this header </td></tr>
    <tr><td class="paramname">length</td><td>the length of the value </td></tr>
    <tr><td class="paramname">p</td><td>pointer to current position in buffer pointer </td></tr>
    <tr><td class="paramname">end</td><td>pointer to end of buffer</td></tr>
  </table>
  </dd>
</dl>
<p>Appends name=value to the headers, but is able to take advantage of better HTTP/2 coding mechanisms where possible. </p>

</div>
</div>
<a class="anchor" id="gacc76a5babcb4dce1b01b1955aa7a2faf"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_add_http_header_content_length </td>
          <td>(</td>
          <td class="paramtype">struct lws *&#160;</td>
          <td class="paramname"><em>wsi</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned long&#160;</td>
          <td class="paramname"><em>content_length</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned char **&#160;</td>
          <td class="paramname"><em>p</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned char *&#160;</td>
          <td class="paramname"><em>end</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
<p><a class="el" href="group__HTTP-headers-create.html#ga2b36bf44405755ff51c1939303b995a8">lws_add_http_header_by_name()</a> - append content-length helper</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">wsi</td><td>the connection to check </td></tr>
    <tr><td class="paramname">content_length</td><td>the content length to use </td></tr>
    <tr><td class="paramname">p</td><td>pointer to current position in buffer pointer </td></tr>
    <tr><td class="paramname">end</td><td>pointer to end of buffer</td></tr>
  </table>
  </dd>
</dl>
<p>Appends content-length: content_length to the headers </p>

</div>
</div>
<a class="anchor" id="ga29b7d6d2ddfdbaff3d8b607e7e3151b6"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_add_http_header_status </td>
          <td>(</td>
          <td class="paramtype">struct lws *&#160;</td>
          <td class="paramname"><em>wsi</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned int&#160;</td>
          <td class="paramname"><em>code</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned char **&#160;</td>
          <td class="paramname"><em>p</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned char *&#160;</td>
          <td class="paramname"><em>end</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
<p><a class="el" href="group__HTTP-headers-create.html#ga29b7d6d2ddfdbaff3d8b607e7e3151b6">lws_add_http_header_status()</a> - add the HTTP response status code</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">wsi</td><td>the connection to check </td></tr>
    <tr><td class="paramname">code</td><td>an HTTP code like 200, 404 etc (see enum http_status) </td></tr>
    <tr><td class="paramname">p</td><td>pointer to current position in buffer pointer </td></tr>
    <tr><td class="paramname">end</td><td>pointer to end of buffer</td></tr>
  </table>
  </dd>
</dl>
<p>Adds the initial response code, so should be called first </p>

</div>
</div>
<a class="anchor" id="ga4887605ff2242a54db3a7fa01f6f864b"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_finalize_http_header </td>
          <td>(</td>
          <td class="paramtype">struct lws *&#160;</td>
          <td class="paramname"><em>wsi</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned char **&#160;</td>
          <td class="paramname"><em>p</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned char *&#160;</td>
          <td class="paramname"><em>end</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
<p><a class="el" href="group__HTTP-headers-create.html#ga4887605ff2242a54db3a7fa01f6f864b">lws_finalize_http_header()</a> - terminate header block</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">wsi</td><td>the connection to check </td></tr>
    <tr><td class="paramname">p</td><td>pointer to current position in buffer pointer </td></tr>
    <tr><td class="paramname">end</td><td>pointer to end of buffer</td></tr>
  </table>
  </dd>
</dl>
<p>Indicates no more headers will be added </p>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
